package com.jerry.springcloud.mapper;

import com.jerry.springcloud.bean.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

//这是Category操作数据库的mapper
@Mapper
public interface CategoryMapper {

    @Select("select * from t_category")
    public List<Category> getCategoryList();

    @Select("select * from t_category where id=#{id}")
    public Category getCategoryById(Integer id);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into t_category(name, type) values(#{name},#{type})")
    public int insertCategory(Category category);

    @Update("update t_category set name=#{name}, type=#{type} where id=#{id}")
    public int updateCategory(Category category);

    @Delete("delete from t_category where id=#{id}")
    public int deleteCategoryById(Integer id);

    /**
     * 注意：以下写法
     * 1，@Select后面的括号包含大括号
     * 2，使用<script>标签
     * 3，@Select后面大括号中的代码，每行后面使用逗号结束
     */
    @Select({
            "<script>",
            "select * from t_category where type in ",
            "<foreach collection='typeList' item='type' open='(' separator=',' close=')'>",
            "#{type}",
            "</foreach>",
            "</script>"
    })
    List<Category> getCategoryListByTypeIn(@Param("typeList") List<Integer> typeList);

}
